package com.zzx.controller;

import com.zzx.domain.Account;
import com.zzx.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;

@org.springframework.stereotype.Controller
@RequestMapping("/account")
public class Controller {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/sp")
    public String sp(){
        return "save";
    }

    @RequestMapping("/save")
    @ResponseBody
    public String save(Account account){
        System.out.println("account/save");
        accountService.save(account);
        return "success";
    }

    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        List<Account> accountList = accountService.findAll();
        for(Account account:accountList){
            System.out.println(account);
        }
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("accountList",accountList);//键值对
        modelAndView.setViewName("accountList");
        return modelAndView;
    }
}
